<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如果变量在函数内没有声明(没使用var关键字)该变量为全局变量</title>
</head>

<body>
    <p>如果你的变量没有声明，它将自动成为全局变量：</p>
    <p id="demo"></p>
    <script>
        myFunction();
        document.getElementById("demo").innerHTML =
            "我可以显示 " + carName;
        function myFunction() {
            carName = "Volo";
        }
    </script>
</body>

</html>